home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 2.toast / pc / sample code / quicktime / wired movies and sprites / desktopsprites.win / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-10-06  |  8.8 KB  |  239 lines

  1. /*
  2.     File:        main.c
  3.     
  4.     Description: Main program
  5.  
  6.     Author:        QuickTime team
  7.  
  8.     Copyright:     © Copyright 1999 Apple Computer, Inc. All rights reserved.
  9.     
  10.     Disclaimer:    IMPORTANT:  This Apple software is supplied to you by Apple Computer, Inc.
  11.                 ("Apple") in consideration of your agreement to the following terms, and your
  12.                 use, installation, modification or redistribution of this Apple software
  13.                 constitutes acceptance of these terms.  If you do not agree with these terms,
  14.                 please do not use, install, modify or redistribute this Apple software.
  15.  
  16.                 In consideration of your agreement to abide by the following terms, and subject
  17.                 to these terms, Apple grants you a personal, non-exclusive license, under Apple’s
  18.                 copyrights in this original Apple software (the "Apple Software"), to use,
  19.                 reproduce, modify and redistribute the Apple Software, with or without
  20.                 modifications, in source and/or binary forms; provided that if you redistribute
  21.                 the Apple Software in its entirety and without modifications, you must retain
  22.                 this notice and the following text and disclaimers in all such redistributions of
  23.                 the Apple Software.  Neither the name, trademarks, service marks or logos of
  24.                 Apple Computer, Inc. may be used to endorse or promote products derived from the
  25.                 Apple Software without specific prior written permission from Apple.  Except as
  26.                 expressly stated in this notice, no other rights or licenses, express or implied,
  27.                 are granted by Apple herein, including but not limited to any patent rights that
  28.                 may be infringed by your derivative works or by other works in which the Apple
  29.                 Software may be incorporated.
  30.  
  31.                 The Apple Software is provided by Apple on an "AS IS" basis.  APPLE MAKES NO
  32.                 WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED
  33.                 WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  34.                 PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN
  35.                 COMBINATION WITH YOUR PRODUCTS.
  36.  
  37.                 IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR
  38.                 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  39.                 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  40.                 ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION
  41.                 OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT
  42.                 (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN
  43.                 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  44.                 
  45.     Change History (most recent first):
  46.  
  47.        <46>         08/30/00    srk        Carbonization
  48.  
  49. */
  50. #pragma once
  51.  
  52. /************************************************************
  53. *                                                           *
  54. *    INCLUDE FILES                                          *
  55. *                                                           *
  56. *************************************************************/
  57.  
  58. #include "main.h"
  59.  
  60. // Windows headers
  61. #define    STRICT
  62. #include <windows.h>
  63.  
  64. /************************************************************
  65. *                                                           *
  66. *    GLOBALS                                                *
  67. *                                                           *
  68. *************************************************************/
  69.  
  70. CGrafPtr gQTMLGraphicsPort = NULL;
  71.  
  72.  
  73. /************************************************************
  74. *                                                           *
  75. *    FUNCTION PROTOTYPES                                    *
  76. *                                                           *
  77. *************************************************************/
  78.  
  79. LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
  80.  
  81.  
  82.  
  83. /************************************************************
  84. *                                                           *
  85. *    WinMain()                                              *
  86. *                                                           *
  87. *                                                           *
  88. *************************************************************/
  89.  
  90. int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
  91.                     PSTR szCmdLine, int iCmdShow)
  92.      {
  93.      static char szAppName[] = "DesktopSprites" ;
  94.      HWND        hwnd ;
  95.      MSG         msg ;
  96.      WNDCLASSEX  wndclass ;
  97.      SpriteWorld theSpriteWorld = NULL;
  98.      RECT        currWinBounds;
  99.      Rect        spriteWindowBounds;
  100.      char        szAppPathName[256];
  101.      FSSpec         resFSSpec;
  102.      short       appResID;
  103.  
  104.  
  105.  
  106.      /* Initialize QuickTime Media Layer */
  107.     if (!QTCode_DoQTInit())
  108.     {
  109.         return 0;
  110.     }
  111.  
  112.     GetModuleFileName(0, szAppPathName, 256);
  113.     NativePathNameToFSSpec(szAppPathName,&resFSSpec,kFullNativePath);
  114.         /* open our resource fork so we can
  115.             access our Mac-style program resources */
  116.     appResID = FSpOpenResFile(&resFSSpec, fsRdPerm);
  117.  
  118.         /* quicktime cannot draw into our window until
  119.             we've created a graphics port for it by 
  120.             calling CreatePortAssociation - see our 
  121.             WndProc procedure below where this is done */
  122.     gQTMLGraphicsPort = NULL;
  123.  
  124.      wndclass.cbSize        = sizeof (wndclass) ;
  125.      wndclass.style         = CS_HREDRAW | CS_VREDRAW ;
  126.      wndclass.lpfnWndProc   = WndProc ;
  127.      wndclass.cbClsExtra    = 0 ;
  128.      wndclass.cbWndExtra    = 0 ;
  129.      wndclass.hInstance     = hInstance ;
  130.      wndclass.hIcon         = LoadIcon (NULL, IDI_APPLICATION) ;
  131.      wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
  132.      wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
  133.      wndclass.lpszMenuName  = NULL ;
  134.      wndclass.lpszClassName = szAppName ;
  135.      wndclass.hIconSm       = LoadIcon (NULL, IDI_APPLICATION) ;
  136.  
  137.      RegisterClassEx (&wndclass) ;
  138.  
  139.      hwnd = CreateWindow (szAppName,         // window class name
  140.                     "Desktop Sprites",       // window caption
  141.                     WS_OVERLAPPEDWINDOW,     // window style
  142.                     CW_USEDEFAULT,           // initial x position
  143.                     CW_USEDEFAULT,           // initial y position
  144.                     CW_USEDEFAULT,           // initial x size
  145.                     CW_USEDEFAULT,           // initial y size
  146.                     NULL,                    // parent window handle
  147.                     NULL,                    // window menu handle
  148.                     hInstance,               // program instance handle
  149.                     NULL) ;                     // creation parameters
  150.  
  151.      ShowWindow (hwnd, iCmdShow) ;
  152.      UpdateWindow (hwnd) ;
  153.  
  154.  
  155.      if (GetWindowRect(hwnd, &currWinBounds))
  156.      {
  157.         QTCode_MapWinRectToQTMLRect(&currWinBounds, &spriteWindowBounds);
  158.      }
  159.      else
  160.      {
  161.          spriteWindowBounds.top = 0;
  162.          spriteWindowBounds.left = 0;
  163.          spriteWindowBounds.bottom = 240;
  164.          spriteWindowBounds.right = 320;
  165.      }
  166.  
  167.         // Create our sprite world & sprites
  168.     theSpriteWorld = QTSprites_CreateSpriteWorld (&spriteWindowBounds, (CGrafPtr)GetHWNDPort(hwnd));
  169.  
  170.      while (GetMessage (&msg, NULL, 0, 0))
  171.     {
  172.         TranslateMessage (&msg) ;
  173.         DispatchMessage (&msg) ;
  174.  
  175.             /* we'll do our drawing only if we have
  176.                 a valid qtml graphics port to draw into */
  177.         if (gQTMLGraphicsPort)
  178.         {
  179.                       // Animate the sprites
  180.             QTSprites_MoveSprites();
  181.  
  182.             SpriteWorldIdle(theSpriteWorld,    /* the sprite world for this operation */
  183.                             0,                /* Contains flags describing actions that may take place during the idle. */
  184.                             0);                /* On return, contains a pointer to flags describing actions that
  185.                                             took place during the idle. */
  186.         }
  187.     }
  188.  
  189.     QTSprites_DisposeSpriteWorld(theSpriteWorld);
  190.  
  191.         /* we're done accessing our Mac-style
  192.             resources so we can close our
  193.             resource file */
  194.     if (appResID != -1)
  195.          CloseResFile(appResID);
  196.  
  197.              /* notify QTML */
  198.     QTCode_QTCleanUp();
  199.  
  200.      return msg.wParam ;
  201.      }
  202.  
  203. /************************************************************
  204. *                                                           *
  205. *    WndProc()                                              *
  206. *                                                           *
  207. *    Standard Win32 Window Procedure                        *
  208. *                                                           *
  209. *    It's here we associate a QuickTime graphics port with  *
  210. *    our window so QuickTime can draw into the window       *
  211. *                                                           *
  212. *************************************************************/
  213.  
  214. LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
  215.      {
  216.  
  217.      switch (iMsg)
  218.       {
  219.       case WM_CREATE :
  220.           {
  221.               /* create a qtml graphics port so qtml can draw into
  222.                     our Win32 window */
  223.             gQTMLGraphicsPort = (CGrafPtr)QTCode_DoCreatePortAssociation(hwnd, NULL, 0L);
  224.             
  225.             return 0 ;
  226.           }
  227.  
  228.       case WM_CLOSE :
  229.                 /* Destroy the port association */
  230.             QTCode_DoDestroyPortAssociation(hwnd);
  231.             gQTMLGraphicsPort = NULL;
  232.  
  233.            PostQuitMessage (0) ;
  234.            return 0 ;
  235.       }
  236.  
  237.      return DefWindowProc (hwnd, iMsg, wParam, lParam) ;
  238.      }
  239.